package com.tax.infrastructure.extension;

import java.util.Objects;

/**
 * duandehui
 * Extension Coordinate(拓展坐标) is used to uniquely position an Extension
 */
public class ExtensionCoordinate {

    /**
     * 拓展名
     */
    private String extensionPointName;

    /**
     * 业务场景唯一身份标识
     */
    private String bizScenarioUniqueIdentity;

    /**
     * 拓展类
     */
    private Class extensionPointClass;

    /**
     * 业务场景
     */
    private BizScenario bizScenario;

    public Class getExtensionPointClass() {
        return extensionPointClass;
    }

    public BizScenario getBizScenario() {
        return bizScenario;
    }

    public static ExtensionCoordinate valueOf(Class extPtClass, BizScenario bizScenario) {
        return new ExtensionCoordinate(extPtClass, bizScenario);
    }

    public ExtensionCoordinate(Class extPtClass, BizScenario bizScenario) {
        this.extensionPointClass = extPtClass;
        this.extensionPointName = extPtClass.getName();
        this.bizScenario = bizScenario;
        this.bizScenarioUniqueIdentity = bizScenario.getUniqueIdentity();
    }

    public ExtensionCoordinate(String extensionPoint, String bizScenario) {
        this.extensionPointName = extensionPoint;
        this.bizScenarioUniqueIdentity = bizScenario;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (null == o) {
            return false;
        }
        if (getClass() != o.getClass()) {
            return false;
        }
        ExtensionCoordinate other = (ExtensionCoordinate) o;
        if (Objects.isNull(bizScenarioUniqueIdentity)){
            if (!Objects.isNull(other.bizScenarioUniqueIdentity)){
                return false;
            }
        }else if (!bizScenarioUniqueIdentity.equals(other.bizScenarioUniqueIdentity)){
            return false;
        }
        if (Objects.isNull(extensionPointName)){
            if (!Objects.isNull(other.extensionPointName)){
                return false;
            }
        }else if (!extensionPointName.equals(other.extensionPointName)){
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + bizScenarioUniqueIdentity == null ? 0 : bizScenarioUniqueIdentity.hashCode();
        result = prime * result + extensionPointName == null ? 0 : extensionPointName.hashCode();
        return result;
    }
}
